package com.zhj.network.udp.chat;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

/**
 * @PackageName:com.zhj.network.chat
 * @ClassName:UdpSenderDemo1
 * @auter: 朱慧杰
 * @date:2020/7/21 0021 13:47
 **/
public class UdpSenderDemo01 {

    public static void main(String[] args) throws Exception {

        DatagramSocket socket = new DatagramSocket(8888);

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        while (true) {
            String msg = reader.readLine();

            byte[] data = msg.getBytes();

            DatagramPacket packet = new DatagramPacket(data, 0, data.length, new InetSocketAddress("localhost",6666));

            socket.send(packet);

            if (msg.equals("bye")) {
                break;
            }
        }

        socket.close();
    }

}
